package com.wh.book.controller;

import com.wh.book.model.UserInfo;
import com.wh.book.service.UserService;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public String login(String userName, String password,HttpSession session) {
        if (!StringUtils.hasLength(userName) ||
                !StringUtils.hasLength(password)) {
            return "用户名或密码为空";
        }
        UserInfo userInfo = userService.getUserInfoByName(userName);
        if (userInfo == null) {
            return "用户名错误";
        }
        if (!password.equals(userInfo.getPassword())) {
            return "密码错误";
        }
        return "";
    }
}
